<?php
	var_dump($_GET);
	date_default_timezone_set('PRC');
	//echo $_GET['search'];
?>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>兄弟连论坛-PHP技术交流</title>
		<link href="../public/home/css/qingkongsuoyougeshi.css" rel="stylesheet" style="text/css" />
		<link href="../public/home/css/css8.css" rel="stylesheet" style="text/css" />
	</head>
	<body>
			<div id="top">
					<div id="top1">
						<div>
							<div>
								<div id="top1a">
									<a href="#">设为首页</a>
									<a href="#">收藏LAMP兄弟连 </a>
									<a href="#">帮助</a>
									<a href="#">推广链接</a>
									<a href="#">社区应用</a>
									<a href="#">最新帖子</a>
									<a href="#">精华区</a>
									<a href="#">社区服务</a>
									<a href="#">会员列表</a>
									<a href="#">统计排行</a>
									<a href="#">搜索</a>
								</div>
								<div style="clear:both"></div>
							</div>
						</div>
						
					</div>
					<div id="top2">
						<div>
							<div>
								<div id="img">
									<img src="../public/home/img/logo.png" />	
									
								</div>
								<div id="denglu">
								
								<?php
									//如果没有获得 用户id
									if(empty($_GET['id'])){
										$id ='';
								?>
								
									<form method="post" action="./doLogin.php">
										<input type="text" name="userName" />
										<input type="password" name="password" />
										<input type="checkbox" name="checkbox" value="jizhu" />
										<span>记住密码</span>
										<a href="#">找回密码</a>
										<input type="submit" name="deng" value="登录" />
										<button type="submit">注册</button>
									</form>
								<?php
									}else{
										//获取 tid ， id
										$id = $_GET['id'];
									
										//		用id 查出头像图片
										$con = mysqli_connect('localhost','root','www');
										mysqli_set_charset($con,'utf8');
										mysqli_select_db($con,'admin');
										$SQL2 = "select * from userDetail where id={$_GET['id']}";
										$result2 = mysqli_query($con,$SQL2);
										$arr2 = mysqli_fetch_assoc($result2);
										//var_dump($arr2);
										
										
										//  	查出user表中用户的权限
										$con = mysqli_connect('localhost','root','www');
										mysqli_set_charset($con,'utf8');
										mysqli_select_db($con,'admin');
										$SQL3 = "select * from user where id={$_GET['id']}";
										$result3 = mysqli_query($con,$SQL3);
										$arr3 = mysqli_fetch_assoc($result3);
										$auths = array('普通用户','管理员');
									
										
										
								?>
									<div id='php'>
										<div id='php1'>
											<div><p>会员名：<?php echo $arr2['name']; ?>; &nbsp;.</p></div>
											<div><p>[<?php echo $auths[$arr3['auth']] ?>]</p></div>
											<div><p>[积分:50]</p></div>
										</div>
										<div id='php2'>
											<div><img src="../public/home/tmp_name/<?php echo $arr2['photo'];?>" /></div>
										</div>
										<div id='php3'>
											<!--<a href='./updateNames.php'>更改个人信息</a>
											<a href='./updateHeadPhoto.php?id=<?php echo $_GET['id']; ?>'>更改头像</a>-->
										</div>
										<div id='php4'>
											<a href='./out.php'>退出</a>
										</div>
										<div style='clear:both'></div>
									</div>
								
								
								
								<?php
									}
								?>
									
									
									<div style="clear:both"></div>
								</div>
								
							</div>
							
						</div>
					</div>
					
					
					
					<div id="top3">
						<div>
							<div>
								<a href="#">技术交流</a>
								<a href="#">兄弟连</a>
								<a href="#">连队趣事</a>
								<a href="#">议事厅</a>
							</div>
						</div>
					</div>
			</div>
			
			<div id="zhong">
				<div id="zhong1">
						
						<?php
							if(empty($_GET['id'])){
						?>
				
						<div>
							<a href='./homePage.php?tid=<?php echo $_GET['tid']; ?>'><img src="../public/home/img/home.gif.png"></a>
							<span>LAMP > PHP技术交流</span>
						</div>
						<?php
							}else{
						?>
							<div>
							<a href='./homePage.php?tid=<?php echo $_GET['tid']; ?>&id=<?php echo $id; ?>'><img src="../public/home/img/home.gif.png"></a>
							<span>LAMP > PHP技术交流</span>
							</div>
						<?php
							}
						?>
				</div>
				<?php
					//链接数据库，用tid查找type类的 类名，图片
					$con = mysqli_connect('localhost','root','www');
					mysqli_set_charset($con,'utf8');
					mysqli_select_db($con,'admin');
					$SQL5 = "select * from type where id={$_GET['tid']}";
					$result5 = mysqli_query($con,$SQL5);
					$arr5 = mysqli_fetch_assoc($result5);
					
						
					
					//准备SQL语句，查询主题帖有多少
					$SQL13 = "select count(*) as shuliang from post where tid={$_GET['tid']}";
					$result13 = mysqli_query($con,$SQL13);
					//获得数量
					$shuliang = mysqli_fetch_assoc($result13)['shuliang'];
					//echo $shuliang;
				?>
				
				
				<div id="zhong2">
					<div>
						<span style='font-size:20px;'>&nbsp;<?php echo $arr5['name']; ?></span>
					</div>
					
					<div>
						<img src="../public/home/img/<?php echo $arr5['img']; ?>" />
						<div>
							<span class="a">今日:</span>
							<span class="b">3</span>
							<span class="a">|主题:</span><!--用SQL13语句 获得主题数量-->
							<span class="b"><?php echo $shuliang; ?></span>
							<span class="a">|贴数:</span>
							<span class="b">9</span>
						</div>
						
						<div>
							<span>PHP基础编程、疑难解答、学习和开发过程中的经验总结等。</span>
						</div>
						<div style="clear:both"></div>
					</div>
				    
					
					
					<div class="lianjie">
						<div>
							<form action='./postList.php' method='get'>
								<input type='text' name='search' style='height:25px;width:150px;' />
								<input type='submit' value='查询提交' />
								<input type='hidden' name='tid' value='<?php echo $_GET['tid']; ?>' />
								<input type='hidden' name='id' value='<?php echo $_GET['id']; ?>' />
							</form>
						</div>
					<?php
						if(!empty($id)){
						
					?>
						<form method="post" action="./report.php">
							<input type="submit" value="发帖" />
							<input type='hidden' name='tid' value='<?php echo $_GET['tid']; ?>' />
							<input type='hidden' name='id' value='<?php echo $id; ?>' />
						</form>
					<?php
						}else{
					?>
						<form>
							<input type='button' value='发帖'/>
						<form>
					
					<?php
						}
					?>
						
					</div>
					
					
					
					<div>
							<span>标题</span>
							<span>作者</span>
							<span>回复</span>
							<span>最后发表</span>
							<div style="clear:left"></div>
					</div>
					
					<?php
							if(isset($_GET['search'])){
								$where = "and title like '%{$_GET['search']}%'";
								$url = "&search={$_GET['search']}";
							}else{
								$where = "";
								$url = "";
							}
						
					
					
						//默认 现在是第一页
						$nowPage = isset($_GET['page']) ? $_GET['page'] : 1;
						//一页显示几行
						$count = 8;
						//当前页面 从哪开始
						$start = ($nowPage - 1)*$count;
						
					
					
						//链接数据库
						$con = mysqli_connect('localhost','root','www');
						mysqli_set_charset($con,'utf8');
						mysqli_select_db($con,'admin');
						//准备SQL语句，查找用户发帖的内容等，
						$SQL7 = "select * from post where tid={$_GET['tid']} {$where} limit {$start},{$count}";
						$result7 = mysqli_query($con,$SQL7);
						
						while($arr7 = mysqli_fetch_assoc($result7)){
							//通过post表中的uid查找出 用户数据
							$SQL8 = "select * from userDetail where id={$arr7['uid']}";
							$result8 = mysqli_query($con,$SQL8);
							$arr8 = mysqli_fetch_assoc($result8);
						
							//查找出userDetail表中用户昵称
							$SQL13 = "select name from userDetail where id={$arr7['uid']}";
							$user_result = mysqli_query($con,$SQL13);
							$userNames = mysqli_fetch_assoc($user_result)['name'];
							// var_dump($arr7);
					?>
					<div class="waikuang">
						<div>
							<div style='width:35px;'>
								<img src="../public/home/img/topichot.gif" />
								<img src="../public/home/img/headtopic_3.gif" />
							</div>
							<div style='width:266px;'>
								<a href='./reply.php?tid=<?php echo $_GET['tid']; ?>&id=<?php echo $id; ?>&pid=<?php echo $arr7['id']; ?>' style='text-decoration:none;'><span class="a1"> <?php echo $arr7['title']; ?> </span></a>
							</div>	
							<div>
								<span class="a1"><?php echo $userNames; ?></span>	
								<span class="b1" style='border:;width:135px;'><?php  echo date('Y-m-d H:i:s',$arr7['ctime']);?></span>	
							</div>
							<div>
								<span class="a1">158/239717</span>
							</div>
							<div>
								<span class="a1">leisheng</span>
								<span class="b1">昨天 16 : 00</span>
							</div>
							<!--<div style="clear:both"></div>-->
						</div>	
					</div>
					<?php
						}
							
						
						
						//判断可不可以有上一页
						if($nowPage > 1){
							$prevPage = $nowPage - 1;
						}else{
							$prevPage = 1;
						}
						//判断可不可以有下一页
						$countSQL = "select count(*) as shuliang from post where tid={$_GET['tid']}";
						//执行SQL语句
						$result9 = mysqli_query($con,$countSQL);
						//获得多少条数据
						$shuliang = mysqli_fetch_assoc($result9)['shuliang'];
						//echo $shuliang;
						//计算总页数
						$pages = ceil($shuliang / $count);
						if($nowPage < $pages){
							$nextPage = $nowPage + 1;
						}else{
							$nextPage = $pages;
						}
					
						
					?>
					
					
					
					
					<br/>
					<div class="lianjie">
						<div>
							<a href="./postList.php?tid=<?php echo $_GET['tid']; ?>&id=<?php echo $id; ?>&page=1">首页</a>
						</div>
						<div>
							<a href="./postList.php?tid=<?php echo $_GET['tid']; ?>&id=<?php echo $id; ?>&page=<?php echo $prevPage.$url; ?>">上一页</a>
						</div>
						<div>
							<a href="./postList.php?tid=<?php echo $_GET['tid']; ?>&id=<?php echo $id; ?>&page=<?php echo $nextPage.$url; ?>">下一页</a>
						</div>
						<div>
							<a href="./postList.php?tid=<?php echo $_GET['tid']; ?>&id=<?php echo $id; ?>&page=<?php echo $pages; ?>">尾页</a>
						</div>
						<!--<form method="post" action="xx.php">
							<input type="submit" value="发帖" />
							<input type='hidden' name='tid' value='<?php echo $_GET['tid']; ?>' />
						</form>-->
						<div style="clear:both"></div>
					</div>
					
					
					
			<div id="dibu">	
					<div id="dibu">
					<div id="alianjie">
						<a href="#">联系我们</a>
						<span>|</sapn>
						<a href="#">无图版</a>
						<span>|</span>
						<a href="#">手机浏览</a>
						<span>|</span>
						<a href="#">清除COOKIES</a>
					</div>
					<div id="dibuwenzi">
						<p>Powered by phpwind v8.7 Certificate Copytight Time now is:08-22 08:45</p>
					</div>
					<div id="gongbeihao">
						<p>©2006-2015 LAMP兄弟连 版权所有 Gzip disabled 京ICP备11018177号 Total 0.040525(s) query 3,京公网安备11011302000117</p>
					</div>
			</div>
					
					
					
					
				</div>
			
			</div>
	</body>
</html>